package com.example.property.utils;

import java.math.BigDecimal;

public class StringUtil {
    public static int getNumberFromString(String str){
        char[] chars = str.toCharArray();
        StringBuilder builder = new StringBuilder();
        for (char c:chars) {
            if(c >= '0' && c <= '9'){
                builder.append(c);
            }
        }
        return Integer.valueOf(builder.toString());
    }

    public static String numberToLen2String(int i){
        if( -1 < i && i < 10){
            return "0" + i;
        }else{
            return i+"";
        }
    }   public static int stringPriceToInt(String price) {
        if (price == null || price.isEmpty()) {
            throw new IllegalArgumentException("Price cannot be null or empty");
        }

        try {
            BigDecimal decimalPrice = new BigDecimal(price);
            return decimalPrice.multiply(new BigDecimal(100)).intValue(); // 将两位小数转换为整数
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid price format", e);
        }
    }

}
